package br.com.nirvana.loteria.util;

import java.io.File;
import java.util.Properties;

import br.com.nirvana.loteria.exception.ConfigurationException;

public class Configuration {

	public static void main(String[] args) {
		try {
			configure();
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	}

	public static void configure() throws ConfigurationException {
		Properties loteriaProps = PropertiesUtil.getLoteriaProperties();

		configureFolder(loteriaProps.getProperty("download_folder"));
		configureFolder(loteriaProps.getProperty("result_folder"));
	}

	private static void configureFolder(String folderURL) throws ConfigurationException {
		try {
			File folder = new File(folderURL);
			if (!folder.exists()) {
				folder.mkdirs();
			} else if (folder.isFile()) {
				throw new ConfigurationException(PropertiesUtil
						.getMessagesProperties().getProperty("invalid_folder"));
			}
		} catch(Exception ex){
			throw new ConfigurationException(ex);
		}
	}
}
